package com.shuziren.controller.candidate;


import com.shuziren.config.GlobalExceptionHandler;
import com.shuziren.core.vo.Result;
import com.shuziren.domain.dto.InterPersonAddDto;
import com.shuziren.domain.dto.InterPersonSelectDto;
import com.shuziren.domain.dto.InterPersonUpdateDto;
import com.shuziren.service.InterPersonService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.lang.management.GarbageCollectorMXBean;

@RestController
@RequestMapping("/interPerson")
public class InterPersonController {

    @Autowired
    private InterPersonService interPersonService;

    /**
     * 添加面试官
     * @param interPerson
     * @return
     */
    @PostMapping("/addInterPerson")
    public Result addInterPerson(@RequestBody @Valid InterPersonAddDto interPerson) {
        interPersonService.addInterPerson(interPerson);
        return Result.success("添加成功");
    }
    /**
     * 修改面试官
     * @param interPerson
     * @return
     */
    @PutMapping("updateInterPerson")
    public Result updateInterPerson(@RequestBody @Valid InterPersonUpdateDto interPerson) {
        if (interPersonService.getById(interPerson.getId())==null){
            return Result.fail("该用户不存在");
        }
        interPersonService.updateInterPerson(interPerson);
        return Result.success("修改成功");
    }
    /**
     * 删除面试官
     * @param id
     * @return
     */
    @DeleteMapping("/deleeteInterPerson/{id}")
    public Result deleteInterPerson(@PathVariable("id") Integer id) {
        if (interPersonService.getById(id)==null){
            return Result.fail("该用户不存在");
        }
        interPersonService.removeById(id);
        return Result.success("删除成功");
    }
    /**
     * 根据id查询面试官
     * @param id
     * @return
     */
    @PostMapping("/getInterPersonById/{id}")
    public Result getInterPersonById(@PathVariable("id") Integer id) {
        if (interPersonService.getById(id)==null){
            return Result.fail("该用户不存在");
        }

        return Result.success(interPersonService.getById(id));
    }
    /**
     * 面试官列表条件查询
     * @param interPersonDto
     * @return
     */
    @PostMapping("/getInterPerson")
    public Result getInterPersonList(@RequestBody @Validated InterPersonSelectDto interPersonDto) {


        return Result.success(interPersonService.selectPage(interPersonDto));
    }
}